package org.nio;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author wind
 * @create 2024-12-31 16:47
 */
public class FileChannelDemo1 {
    public static void main(String[] args) throws IOException {
        RandomAccessFile raf = new RandomAccessFile("Data.txt", "rw");
        FileChannel fc = raf.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(10);
        int r = fc.read(buf);
        while(r != -1){
            buf.flip();
            while(buf.hasRemaining()){
                System.out.println((char)buf.get());
            }
            buf.clear();
            r = fc.read(buf);
        }
    }
}
